package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2023-10-27
 * Time: 15:07
 */





class Animal {
    public String name;

    public int age;

    public void eat() {
        System.out.println(this.name + "正在吃饭!");
    }
}

class Dog extends Animal{

    public void bark() {
        System.out.println(this.name + "正在汪汪汪!");
    }

}

class Cat extends Animal{

    public void mew() {
        System.out.println(this.name + "正在喵喵喵! ");
    }
}

public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog();
        // dog类中并没有定义任何成员变量，name和age属性肯定是从父类Animal中继承下来的
        System.out.println(dog.name);
        System.out.println(dog.age);

        //dog访问的eat()方法也是从Animal中继承下来的
        dog.eat();
    }
}
